/**
 * 2
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-24 下午8:29
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    int f[n + 1][t + 1];

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= t; ++j) {
            if (i == 0) {
                f[i][j] = 0;
                continue;
            }
            if (j == 0) {
                f[i][0] = f[i - 1][0];
                for (int k = 1; k <= c[i - 1]; ++k) {
                    f[i][0] = max(f[i][0], f[i - 1][k]);
                }
            } else
                if (j + c[i - 1] <= t) {
                f[i][j] = f[i - 1][j + c[i - 1]];
            } else {
                f[i][j] = 0;
            }
            if (j >= a[i - 1]) f[i][j] = max(f[i][j], f[i - 1][j - a[i - 1]] + b[i - 1]);
        }
    }

    int res = 0;

    for (int i = 0; i <= t; ++i) {
        res = max(res,f[n][i]);
    }

    cout << res;

    return 0;
}